// index.js
// 获取应用实例
const app = getApp()
import {
    util,
    Toast,
    Dialog,
    commonMixin
} from "../../utils/util.js";


Page({
    behaviors: [commonMixin],
    data: {
        categories: [],
        categoryId: '',
        list: [],
        activeIndex: 0,
    },
    onLoad() {
        wx.showLoading({
            title: '加载中',
        })
        util.http.post("v1/mini/check-item-categories", {}).then((res) => {
            if (res.data.code == 0) {
                this.setData({
                    categoryId: res.data.data[0].id,
                    categories: res.data.data
                })
                this.getCheckItems()
            } else {
                Toast(res.data.message);
            }
            wx.hideLoading();
        }).catch((err) => {
            wx.hideLoading();
            Toast('网络异常！刷新后重试！');
            console.log(err)
        })
    },
    onShow() {

    },
    onShareAppMessage() {

    },
    handleJumpDetail: function (event) {
      let {
        index,
        id
      } = event.currentTarget.dataset;
      wx.navigateTo({
        url: '/pages/goods/index?id=' + id // 假设详情页的路径是 /pages/detail/detail  
      });
    },
    handleTab: function (event) {
        let {
            index,
            id
        } = event.currentTarget.dataset;
       
        this.setData({
            categoryId: id,
            activeIndex: index
        });;
        this.getCheckItems();
    },
    getCheckItems() {
        let {
            categoryId
        } = this.data;
        wx.showLoading({
          title: '加载中',
      })
        util.http.post("v1/mini/check-item-get-list", {
            goods_category_id: categoryId
        }).then((res) => {
            if (res.data.code == 0) {
                this.setData({
                    list: res.data.data
                })
            } else {
                Toast(res.data.message);
            }
            wx.hideLoading();
        }).catch((err) => {
            wx.hideLoading();
            Toast('网络异常！刷新后重试！');
            console.log(err)
        })
    }
})
